package BackEnd;

import java.sql.Timestamp;
import java.util.Date;

public class TimeManager {
	private static TimeManager instance = null;
	private OptionManager optMan = null;
	
	public TimeManager(){
		optMan = OptionManager.getInstance();
	}
	
	public static synchronized TimeManager getInstance(){
		if(instance == null){
			instance = new TimeManager();
		}
		return instance;
	}
	
	public long calculateSleepTimeForAuftragPlanung(){
		Date actTime = optMan.parseDate(new Timestamp(System.currentTimeMillis()));
		Date endDate = optMan.getEndDate();
		Date startDate = optMan.getStartDate();
		if (actTime.after(endDate)){
			startDate.setDate(2);
		}
		else if (actTime.before(startDate)){
			startDate.setDate(2);
			actTime.setDate(2);
		}
		return Math.abs(actTime.getTime() - startDate.getTime());
	}
	
	/*public boolean isWeekend(){
		Date actTime = optMan.parseDate(new Timestamp(System.currentTimeMillis()));
		 if (actTime.getDay()==6 || actTime.getDay()==0){
			 return true;
		 } else
			 return false;
	}*/
	
	public boolean isActualTimeOutsideBoersenZeit(){
		Date actTime = optMan.parseDate(new Timestamp(System.currentTimeMillis()));
		Date endDate = optMan.getEndDate();
		Date startDate = optMan.getStartDate();
		if (actTime.after(endDate)){
			startDate.setDate(2);
		}
		else if (actTime.before(startDate)){
			startDate.setDate(2);
			actTime.setDate(2);
		}
	
		if ((actTime.after(endDate) && actTime.before(startDate))){
			return true;
		} else
			return false;
	}
}
